package com.zoroki.student_score_system.controller;

import com.zoroki.student_score_system.domain.Semester;
import com.zoroki.student_score_system.service.SemesterService;
import com.zoroki.student_score_system.utils.Msg;
import com.zoroki.student_score_system.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/semester")
public class SemesterController {
    @Autowired
    SemesterService semesterService;


    @GetMapping("/findAllSemesters")
    public @ResponseBody Result<List<Semester>> findAllSemesters() {
        return new Result<List<Semester>>(0,semesterService.findAllSemesters(), Msg.SUCCESS);
    }

    @GetMapping("/findSemesterById")
    public @ResponseBody Result<Semester> findSemesterById(int studentId) {
        return new Result<Semester>(0,semesterService.findSemesterById(studentId), Msg.SUCCESS);
    }


    @PostMapping("/addSemester")
    public @ResponseBody Result<Boolean> addSemester(@RequestBody Semester semester) {
        return new Result<Boolean>(0,semesterService.addSemester(semester), Msg.SUCCESS);
    }

    @PostMapping("/updateSemester")
    public @ResponseBody Result<Boolean> updateSemester(@RequestBody Semester semester) {
        return new Result<Boolean>(0,semesterService.updateSemester(semester), Msg.SUCCESS);
    }

    @PostMapping("/deleteSemester")
    public @ResponseBody Result<Boolean> deleteSemester(int id) {
        return new Result<Boolean>(0,semesterService.deleteSemester(id), Msg.SUCCESS);
    }

}
